classdef EffectFlangerWindow < handle
    %%EFFECTFLANGERGUI Dooku Synthesizer Flanger Effect window GUI class
    properties
        % Figure variables
        hfig;
        handles;

        % Effect data
        Data;
    end
    
    properties (SetObservable)
        finish;
    end
    
    methods
        
        function obj = EffectFlangerWindow
            % Figure Load
            obj.hfig = hgload('EffectFlangerGUI.fig');
            obj.handles = guihandles(obj.hfig);
            
            % Callbacks Definitions
            set(obj.handles.instrumentWindow, 'CloseRequestFcn', @(src, event) finishSelect(obj, src, event));
            set(obj.handles.variationEdit, 'Callback', @(src, event) variationChange(obj, src, event));
            set(obj.handles.rateEdit, 'Callback', @(src, event) rateChange(obj, src, event));
            
            obj.defaultVariables();
        end
        
        function defaultVariables(obj)
            obj.Data.name = 'Flanger';
            obj.Data.variation = 0.05;
            obj.Data.rate = 1;
        end
        
        function visible(obj)
            set(obj.hfig, 'Visible', 'on');
            set(obj.hfig, 'Windowstyle', 'modal');
        end
        
        function refreshWindow(obj, dataIn)
            obj.Data = dataIn;
            set(obj.handles.variationEdit, 'String', num2str(obj.Data.variation));
            set(obj.handles.rateEdit, 'String', num2str(obj.Data.rate));
        end
        
        function instrumentData = saveData(obj)
            
        end
        
        function obj = variationChange(obj, ~, ~)
            variationAux = str2double(get(obj.handles.variationEdit, 'String'));
            if sum(isnan(variationAux)) || sum(variationAux <= 0)
                errordlg('Variation must be a positive numeric number.', 'Inconsistent error');
                set(obj.handles.variationEdit, 'String', obj.Data.variation);
            else
                obj.Data.variation = variationAux;
            end
        end
        
        function obj = rateChange(obj, ~, ~)
            rateAux = str2double(get(obj.handles.rateEdit, 'String'));
            if sum(isnan(rateAux)) || sum(rateAux <= 0)
                errordlg('Rate must be a positive numeric number.', 'Inconsistent error');
                set(obj.handles.rateEdit, 'String', obj.Data.rate);
            else
                obj.Data.rate = rateAux;
            end
        end
        
        function obj = finishSelect(obj, ~, ~)
            obj.finish = 1;
            set(obj.hfig, 'Visible', 'off');
            set(obj.hfig, 'Windowstyle', 'normal');
        end
        
    end
    
end